Ext.regModel('E_Mail', {
	fields : [ 
	{		
		name : 'pageIndex',
		type : 'int'
	}, {		
		name : 'sender',
		type : 'string'
	}, {
		name : 'subject',
		type : 'string'
	}, {
		name : 'attachment',
		type : 'string'
	}, {
		name : 'receivedDate',
		type : 'string'
	}, {
		name : 'content',
		type : 'string'
	} ]
});

// 4. 데이터 접근.
function mailData()
{
    // 데이터 읽기.
    var record              = mailStore.getAt(0);   
    console.log(record);   
    console.log(record.data.id);
    console.log(record.data.firstName);
    console.log(record.data["lastName"]);
}

var objStoreListener = {
	add : function() {
		console.log("add");
	},
	beforeload : function() {
		console.log("beforeload");
	},
	datachanged : function() {
		console.log("datachanged");
	},
	exception : function() {
		console.log("exception");
	},
	load : function() {
		console.log("load");
	},
	remove : function() {
		console.log("remove___");
	},
	update : function() {
		console.log("loadexception");
	}
}

var mailProxy = new Ext.data.AjaxProxy({
	url: '../readJsonGMail.do',
    type:'ajax',
    model: 'E_Mail',
    reader:{
        type:'json',
        root:'result'
    }
});

// 3. Store생성.
var mailStore = new Ext.data.JsonStore({
	model : 'E_Mail',
	encode: 'true',
    proxy: mailProxy
});
mailStore.sort('receivedDate', 'DESC');
mailStore.load();

var mailList = new Ext.List( {
	fullscreen : true,
	store : mailStore,
	itemTpl : '<div class="mail_service"><strong>sender</strong> : {sender}<br/><strong>subject</strong> : {subject}<br/>' +
				'<strong>received date</strong> : {receivedDate}</div>',
	listeners : {
		itemtap : function(dv, ix, item, e) {
			var rec = mailStore.getAt(ix);
			var popPanel = new Ext.Panel({
                floating: true,
                store : mailStore,
                centered: true,
                width: Ext.is.Phone ? 400 : 1000,
                height:Ext.is.Phone ? 500 : 600,
                styleHtmlContent: true,
                html: '<div class="mail_content"><strong>sender</strong> : ' + rec.data.sender + '<br/><strong>subject</strong> : ' + rec.data.subject +  
                '<br/><strong>received date</strong> : ' + rec.data.receivedDate + '<br/><strong>content</strong><br/>' + rec.data.content,
                dockedItems: [{
			    	xtype: 'toolbar',
			    	dock: 'top',
			        title: 'Board Content'
			    }, {
			    	xtype: 'button',
			    	text: 'close',
			    	handler: function() {
			    		popupPanel.hide();
			    	}
			    }],
                scroll: 'vertical'
            });
			if (!this.popup) {
                this.popup = popPanel;
            }
            this.popup.show('pop');
		}
	},
} );